#include <iostream>
#include <cstring>

using namespace std;

int add(int a, int b) {
    return a + b;
}

double add(double a, double b) {
    return a + b;
}

char *add(const char *a, const char *b) {
    int a_len = strlen(a);
    int b_len = strlen(b);
    int buf_len = a_len + b_len;
    char buffer[buf_len + 1];

    strcat(buffer, a);
    strcat(buffer, b);

    return buffer;  // warning: address of stack memory associated with local variable
}

void add(const char *a, const char *b, char *dest) {
    strcat(dest, a);
    strcat(dest, b);
}

int main(void)
{
    cout << add(1, 2) << endl;
    cout << add(1.1, 2.2) << endl;
    cout << add("hello", "world") << endl;

    char buffer[50] = { 0 };
    add("I am ", "Huoty", buffer);
    cout << buffer << endl;

    return 0;
}

